package com.scau.database.controller.salesperson;

import com.scau.database.entity.salesperson.sell.BuyResultDTO;
import com.scau.database.entity.salesperson.sell.SellVO;
import com.scau.database.service.salesperson.SellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/store")
public class SellController {
    @Autowired
    private SellService sellService;
    @GetMapping("/{storeId}/commodity")
    public SellVO getCommodity(@PathVariable("storeId") Integer storeId, HttpServletRequest httpServletRequest){
        String barCode = httpServletRequest.getParameter("barCode");
        String shelfId = httpServletRequest.getParameter("shelfId");
        String orderId = httpServletRequest.getParameter("orderId");
        // orderId暂时不使用
//        System.out.println("barCode:"+ barCode + "\n shelfId : "+ shelfId + " \n orderId:"+orderId);
        if (barCode == null || shelfId == null ){
            // 调用扫描模拟器
            return sellService.getSell(storeId);
        }else{
            Long shelfIdL = Long.valueOf(shelfId);
//            Long orderIdL = Long.valueOf(orderId);
            return sellService.getSell(storeId,barCode,shelfIdL);
        }
    }
    @PostMapping("/{storeId}/buy")
    public BuyResultDTO buy(@PathVariable("storeId") Integer storeId, @RequestBody List<SellVO> sellVOS){
        return sellService.buy(storeId,sellVOS);
    }

}
